package com.zc.controller.newController;

import com.zc.dto.ResultDto;
import com.zc.service.JedisClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/redis")
public class RedisController {
    private final Logger logger  = LoggerFactory.getLogger(this.getClass());
    @Resource
    private JedisClient jedis;
    @ResponseBody
    @RequestMapping(value = "/jedisPublish",method = RequestMethod.POST)
    public ResultDto jedisPublish(String message){
        ResultDto result = new ResultDto();
        try {
            jedis.publish("redisMessage",message);
            //模拟起见,直接在初始化时就订阅固定频道,具体使用见机行事
            result.setMessage("success");
            result.setSuccess(true);
        }catch (Exception e){
            logger.error("jedisPublish error ::,{}",e);
            result.setSuccess(false);
            result.setMessage("false");
        }
        return result;
    }
}

